package com.dao; 

import java.text.*; 
 import java.util.*; 
 import java.sql.*; 

import com.adopters.ConnectionManager;
import com.beans.AddBugBean;
import com.beans.UserBean;
 
 public class AddBugDAO { 
	 static Connection con = null; 
	 static int status ;
	 static boolean insFlag = false;
	 public static boolean addbug(AddBugBean bean) {
		 
		 
		 
		 //preparing some objects for connection 
		 Statement stmt = null;
		 String desc = bean.getDesc();
		 int priority=bean.getPriority();
		 String assignto = bean.getAssignedTo();
		 
		// String insertQuery = "insert into bug_details values('" + desc + "',"+priority+",'"+assignto+"')"; 
		 String insertQuery = "insert into bug_details values('"+desc+"'"+","+priority+","+"'"+assignto+"')";
		 			 
		 try { 
			 //connect to DB 
			 con = ConnectionManager.getConnection();
			 stmt=con.createStatement(); 
			 status = stmt.executeUpdate(insertQuery); 
			
			 // if Error while inserting 
			 if (status!=1) {
				 System.out.println("Error in adding bug");
				 insFlag = false; 
			}
			 
			 //if insertion succesful
			else if (status==1) { 
				
				bean.setBugId(1); 
				insFlag = true;
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		 //some exception handling 
		finally { 
			 
		}
		return insFlag; 
	}
}
